home *** CD-ROM | disk | other *** search
/ SGI ONC3 NFS v2 / SGI ONC3 NFS v2.iso / dist6.4 / nfs.idb / var / boot / .dl_inst.z / .dl_inst (.txt)
Text File  |  1997-02-07  |  8KB  |  377 lines

  1. #! /bin/sh
  2. #ident  "$Revision: 1.68 $"
  3. #
  4. #
  5. # Following variables should be read from file /var/boot/$RELEASE.dat
  6. #
  7. #DISKLESS="/usr/tmp"
  8. #CLROOT="$DISKLESS/$HOST"
  9. #SHAREHOST="$HOSTNAME"
  10. #SHARE="$DISKLESS/$CLASS"
  11. #SWAP="$DISKLESS/swap/$HOST"
  12. #SWAPSIZE="10m"
  13. #NIS="yes"
  14. #DLMAJOR=18    A long time ago NFS used its own major number
  15. #
  16. # Following variables should be read from file /var/boot/$CLASS.dat
  17. #
  18. #GFXBOARD="ECLIPSE"
  19. #CPUBOARD="IP6"
  20. #CPUARCH="R3000"
  21. #VIDEO=""
  22. #
  23. # The following variables are "server-relative"
  24. #
  25. DIR="/var/boot"
  26. MKFILE="/usr/sbin/mkfile"
  27. #
  28. # The following variables are "client-relative"
  29. #
  30. BOOT=$CLROOT/var/sysgen/boot
  31. SHELL="/sbin/sh"
  32. NIS_DIR="/var/yp"
  33. NIS_EXEC_DIR="/usr/sbin"
  34. SGI_CC=-cckr; export SGI_CC
  35. NFS_INSTALL="no"
  36. PATH="/usr/sbin:/usr/bsd:/sbin:/usr/bin:/bin:/etc:/usr/etc:/usr/bin/X11"
  37. export PATH
  38. INST="${INSTALL_TOOL:-/usr/sbin/inst}"
  39. case $INST in
  40. *swmgr )
  41.     INST_OPT="-Vbackground:off"
  42.     ;;
  43. *inst)
  44.     INST_OPT=""
  45.     ;;
  46. *)
  47.     echo "Unknown install mechanism"
  48.     exit 1
  49.     ;;
  50. esac
  51.  
  52.  
  53. #
  54. #
  55.  
  56. CMDNAME=$0
  57. TARGET=""
  58.  
  59. #
  60. # Run exportfs on server
  61. #
  62. #    No arguments
  63. #
  64. run_exportfs()
  65. {
  66.     if [ -x /usr/etc/exportfs ]; then
  67.         /usr/etc/exportfs $1
  68.         case $? in
  69.         0)
  70.             ;;
  71.         *)
  72.             echo "ATTENTION: fix /etc/exports and rerun exportfs !"
  73.             echo "ATTENTION: fix /etc/exports and rerun exportfs !" >> /dev/console
  74.             exit 1
  75.             ;;
  76.         esac
  77.     else
  78.         echo "ATTENTION: /usr/etc/exportfs does not exist !"
  79.         echo "ATTENTION: /usr/etc/exportfs does not exist !" >> /dev/console
  80.         exit 1
  81.     fi
  82. }
  83.  
  84. #
  85. # Create /etc/exports if it does not exist.
  86. #
  87. #    No arguments
  88. #
  89. create_exports()
  90. {
  91.     if [ ! -f /etc/exports ]; then
  92.         > /etc/exports
  93.         chmod 644 /etc/exports
  94.     fi
  95. }
  96.  
  97. #
  98. # Update client exports on server
  99. #
  100. # Any swap partitions must be exported with the wsync flag.  This will force
  101. # accesses to NFS swap to be synchronous.  Without this, we have a good chance
  102. # on a heavily loaded client system to have random programs core dump when a
  103. # server recovers after a crash.
  104. #
  105. #    arguments: 1 -- export directory.
  106. #           2 -- class/client KEY.
  107. #           3 -- swap/noswap argument
  108. #
  109. export_client_dir()
  110. {
  111.     if [ "$NFS_INSTALL" = "yes" ]; then
  112.         echo "\nPlease export this entry on the NFS server: "
  113.         if [ "$3" = "swap" ]; then
  114.             echo "    $1 -rw=$2,wsync,access=$2,root=$2    #host=$2"
  115.         else
  116.             echo "    $1 -rw=$2,access=$2,root=$2    #host=$2"
  117.         fi
  118.         return;
  119.     fi
  120.  
  121.     create_exports
  122.  
  123.     # Add export line to /etc/exports
  124.     grep $1 /etc/exports >/dev/null 2>&1
  125.     if [ $? -eq 1 ]; then
  126.         if [ "$3" = "swap" ]; then
  127.             echo "$1 -rw=$2,wsync,access=$2,root=$2    #host=$2" \
  128.                 >> /etc/exports
  129.         else
  130.             echo "$1 -rw=$2,access=$2,root=$2    #host=$2" \
  131.                 >> /etc/exports
  132.         fi
  133.     fi
  134.  
  135.     run_exportfs $1
  136. }
  137.  
  138.  
  139. #
  140. # Update shareable exports on server
  141. #
  142. #    arguments: 1 -- export directory.
  143. #           2 -- export privileges
  144. #           3 -- class/client KEY.
  145. #
  146. export_share_dir()
  147. {
  148.     if [ $2 != "rw" -a $2 != "ro" ]; then
  149.         echo "\nIllegal flag to export_share_dir"
  150.         exit
  151.     fi
  152.  
  153.     if [ "$NFS_INSTALL" = "yes" ]; then
  154.         echo "\nPlease export this entry on the NFS server: "
  155.         echo "    $1 -$2    #class=$3"
  156.         return;
  157.     fi
  158.  
  159.     create_exports
  160.  
  161.     # Add export line to /etc/exports
  162.     grep $1 /etc/exports >/dev/null 2>&1
  163.     if [ $? -eq 1 ]; then
  164.         echo "$1 -$2    #class=$3" >> /etc/exports
  165.     fi
  166.  
  167.     run_exportfs $1
  168. }
  169.  
  170.  
  171. #
  172. #    Unexports directories on server.
  173. #
  174. #        Arguments: 1 -- type
  175. #               2 -- directory
  176. #               3 -- key
  177. #
  178. unexport_dir()
  179. {
  180.     if [ "$1" != "class" -a "$1" != "host" ]; then
  181.         echo "Illegal type to unexport_dir"
  182.         exit 1;
  183.     fi
  184.     if [ "X$2" = "X" ]; then
  185.         echo "No directory argument to unexport_dir";
  186.         exit 1;
  187.     fi
  188.     if [ ! -d "$2" ]; then
  189.         echo "Illegal directory argument to unexport_dir";
  190.         exit 1;
  191.     fi
  192.     if [ "X$3" = "X" ]; then
  193.         echo "No key argument to unexport_dir";
  194.         exit 1;
  195.     fi
  196.     if [ "X$NFS_INSTALL" = "Xyes" ]; then
  197.         echo "Please unexport the NFS server entry for: \c"
  198.         echo $3
  199.         rm -r $2
  200.         return
  201.     fi
  202.  
  203.     if [ ! -f /etc/exports ]; then
  204.         echo "ATTENTION: /etc/exports does not exist !" >> /dev/console
  205.         echo "ATTENTION: /etc/exports does not exist !"
  206.         exit 1
  207.     fi
  208.  
  209.     if [ -x /usr/etc/exportfs ]; then
  210.         /usr/etc/exportfs -u "$2" > /dev/null 2>&1
  211.     else
  212.         echo "ATTENTION: /usr/etc/exportfs does not exist !"
  213.         echo "ATTENTION: /usr/etc/exportfs does not exist !" >> /dev/console
  214.         exit 1
  215.     fi
  216.  
  217.     if [ "$1" = "class" ]; then
  218.         grep -v "$2.*\#class=$3" /etc/exports > /etc/export.$$
  219.     else
  220.         grep -v "$2.*\#host=$3" /etc/exports > /etc/export.$$
  221.     fi;
  222.  
  223.     rm -r $2
  224.     mv /etc/export.$$ /etc/exports
  225. }
  226.  
  227.  
  228. #
  229. #    poke_host
  230. #
  231. #        Argument: 1 -- hostname.
  232. #              2 -- NIS option.
  233. #              3 -- TARGET.
  234. #
  235. #        return:   0 -- host is neither CLASS not CLIENT.
  236. #              1 -- host is not running.
  237. #              2 -- host in running.
  238. #
  239. poke_host()
  240. {
  241.     POKEHOST="$1";
  242.     POKENIS="$2";
  243.     POKETARGET="$3";
  244.  
  245.     RETVAL=0;
  246.     if [ "$POKENIS" = "yes" ]; then
  247.         ypmatch "$POKEHOST" bootparams > /dev/null 2>&1;
  248.         if [ $? -eq 0 ]; then
  249.             RETVAL=1;
  250.         fi;
  251.     fi;
  252.     if [ "$NFS_INSTALL" = "yes" ]; then
  253.         return 1;
  254.     fi
  255.     if [ "$POKENIS" != "yes" -o "$RETVAL" -eq 0 ]; then
  256.         if [ ! -f /etc/bootparams ]; then
  257.             return 0;
  258.         fi
  259.         grep "$POKEHOST" /etc/bootparams | while read a_line; do
  260.             set $a_line;
  261.             if [ "$1" = "$POKEHOST" ]; then
  262.                 return 1;
  263.             fi;
  264.         done
  265.         RETVAL=$?;
  266.     fi;
  267.  
  268.     if [ "$POKETARGET" = "share" -o "$RETVAL" -eq 0 ]; then
  269.         return "$RETVAL";
  270.     fi
  271.  
  272.     if [ `ping -s 56 -c 5 $POKEHOST | wc -l` -gt 6 ]; then
  273.         RETVAL=2;
  274.     fi
  275.  
  276.     return "$RETVAL";
  277. }
  278.  
  279. #
  280. #    poke_class
  281. #
  282. #        Argument: 1 -- share tree.
  283. #              2 -- NIS option.
  284. #              3 -- ACTION.
  285. #              4 -- CLASS.
  286. #
  287. #        return:   0 -- continue
  288. #              1 -- abort.
  289. #
  290. poke_class()
  291. {
  292.     POKESHARE="$1";
  293.     POKENIS="$2";
  294.     POKEACT="$3";
  295.     POKECLASS="$4";
  296.  
  297.     if [ "$POKENIS" = "yes" ]; then
  298.         ypcat bootparams | grep "share=${POKESHARE}" 2>&1 > /dev/null
  299.         if [ $? -eq 0 ]; then
  300.         echo "\nWARNING: Class $POKECLASS is still serving clients."
  301.         if [ "$POKEACT" = "delete" ]; then
  302.             echo "continue to delete $POKECLASS(Y/N)\07?\c"
  303.         else
  304.             echo "continue to update $POKECLASS(Y/N)\07?\c"
  305.         fi;
  306.         read CONF
  307.         if [ "$CONF" != "y" -a "$CONF" != "Y" ]; then
  308.             return 1;
  309.         fi;
  310.         echo "\nChecking clients status:\n"
  311.         ypcat -k bootparams | grep "share=${POKESHARE}" | while read a_line; do
  312.             set $a_line;
  313.             echo "        $1 ... \c"
  314.             if [ `ping -s 56 -c 5 $1 | wc -l` -gt 6 ]; then
  315.                 echo "UP";
  316.             else
  317.                 echo "DOWN";
  318.             fi
  319.         done
  320.  
  321.         echo "\nWARNING: clients will be out of sync. Clients which are UP may crash.\n"
  322.         return 0;
  323.         fi;
  324.     fi;
  325.     if [ "$NFS_INSTALL" = "yes" ]; then
  326.         echo "Warning: $POKECLASS may be active.  Not checking server"
  327.         if [ "$POKEACT" = "delete" ]; then
  328.             echo "continue to delete $POKECLASS(Y/N)\07?\c"
  329.         else
  330.             echo "continue to update $POKECLASS(Y/N)\07?\c"
  331.         fi;
  332.         read CONF
  333.         if [ "$CONF" != "y" -a "$CONF" != "Y" ]; then
  334.             return 1;
  335.         fi
  336.         return 0;
  337.     fi
  338.  
  339.     if [ ! -f /etc/bootparams ]; then
  340.         if [ "$POKEACT" = "delete" ]; then
  341.             return 1;
  342.         else
  343.             return 0;
  344.         fi;
  345.     fi
  346.  
  347.     grep "share=${POKESHARE}" /etc/bootparams 2>&1 > /dev/null
  348.     if [ $? -ne 0 ]; then
  349.         return 0;
  350.     fi
  351.  
  352.     echo "\nWARNING: Class $POKECLASS is still serving clients."
  353.     if [ "$POKEACT" = "delete" ]; then
  354.         echo "continue to delete $POKECLASS(Y/N)\07?\c"
  355.     else
  356.         echo "continue to update $POKECLASS(Y/N)\07?\c"
  357.     fi;
  358.     read CONF
  359.     if [ "$CONF" != "y" -a "$CONF" != "Y" ]; then
  360.         return 1;
  361.     fi;
  362.     echo "\nChecking client's status:\n"
  363.     grep "share=${POKESHARE}" /etc/bootparams | while read a_line; do
  364.         set $a_line;
  365.         echo "    client $1 ... \c"
  366.         if [ `ping -s 56 -c 5 $1 | wc -l` -gt 6 ]; then
  367.             echo "UP";
  368.         else
  369.             echo "DOWN";
  370.         fi
  371.     done
  372.  
  373.     echo "\nWARNING: clients will be out of sync. Clients which are UP may crash.\n"
  374.     return 0;
  375.  
  376. }
  377.